package com.willie.elasticjob.controller;

import com.willie.elasticjob.entity.ElasticJobConfig;
import com.willie.elasticjob.service.ElasticJobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("job")
public class JobController {

    private Logger log = LoggerFactory.getLogger(JobController.class);

    @Autowired
    private ElasticJobService elasticJobService;

    @PostMapping("addElasticJobConfig")
    @ResponseBody
    public Object addOrUpdateElasticJobConfig(ElasticJobConfig ElasticJobConfig) {
        log.info("更新或新增 {} ", ElasticJobConfig.toString());
        return elasticJobService.insert(ElasticJobConfig);
    }

    @PostMapping("UpdateElasticJobConfig")
    public Object updateElasticJobConfig(ElasticJobConfig ElasticJobConfig) {
        log.info("更新{} ", ElasticJobConfig.toString());
        return elasticJobService.update(ElasticJobConfig);
    }

    @GetMapping("getElasticJobConfig")
    @ResponseBody
    public ElasticJobConfig getElasticJobConfig(String id) {
        return elasticJobService.getElasticJobConfigById(id);
    }

    @PostMapping("delete")
    @ResponseBody
    public void delete(String id) {
        elasticJobService.delete(id);
    }
}
